package lfm.mpr;

import lfm.mpr.R;
import lfm.mpr.R.drawable;
import lfm.mpr.R.id;
import lfm.mpr.R.layout;
import lfm.mpr.R.menu;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;


 public class TabHost_Liga extends TabActivity {
	 
	 
	 private TabHost tabHost;
	 public static String Liga_Name = "";
	 public static String Liga_Id = "";
	 public static String Liga_status = "";
	 private SharedPreferences prefs;
	 
	 @Override
	 public void onCreate(Bundle savedInstanceState) {
		 
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.tabhost_liga);
	        
	        Resources res = getResources();
	        prefs = getSharedPreferences("MisPreferencias",Context.MODE_PRIVATE);
	        
	      
	        tabHost = getTabHost();
	        tabHost.setup();
	        
	        
	        final Bundle extras = getIntent().getExtras(); 
            if(extras !=null)
            {
            	Liga_Name = extras.getString("liga");
            	Liga_Id = extras.getString("ligaid");
            	Liga_status = extras.getString("ligastatus");
            }
	        
	        TabSpec user_liga_spec = tabHost.newTabSpec("Usuarios");
	        // setting Title and Icon for the Tab
	        user_liga_spec.setIndicator("Usuarios", getResources().getDrawable(R.drawable.user_group));
	        Intent UserLigaIntent = new Intent(this, UsersLigaActivity.class);
	        user_liga_spec.setContent(UserLigaIntent);
	        
	        TabSpec teams_liga_spec = tabHost.newTabSpec("Equipos");
	        // setting Title and Icon for the Tab
	        teams_liga_spec.setIndicator("Equipos", getResources().getDrawable(R.drawable.new_team));
	        Intent TeamsLigaIntent = new Intent(this, TeamsLigaActivity.class);
	        teams_liga_spec.setContent(TeamsLigaIntent);
	        
	        TabSpec jornadas_liga_spec = tabHost.newTabSpec("Clas.Jornadas");
	        // setting Title and Icon for the Tab
	        jornadas_liga_spec.setIndicator("Clas.Jornadas", getResources().getDrawable(R.drawable.clas_jornada));
	        Intent JornadasLigaIntent = new Intent(this, Clasificacion_Jornada_Activity.class);
	        JornadasLigaIntent.putExtra("Liga_Name", Liga_Name);
	        JornadasLigaIntent.putExtra("Liga_Id", Liga_Id);
	        jornadas_liga_spec.setContent(JornadasLigaIntent);
	        
	        TabSpec General_liga_spec = tabHost.newTabSpec("Clas.General");
	        // setting Title and Icon for the Tab
	        General_liga_spec.setIndicator("Clas.General", getResources().getDrawable(R.drawable.clas_general));
	        Intent GeneralLigaIntent = new Intent(this, Clasificacion_General_Activity.class);
	        General_liga_spec.setContent(GeneralLigaIntent);
	         
	        if(Liga_status.equals("Pendiente")){
	        	tabHost.addTab(user_liga_spec);
	        	tabHost.addTab(teams_liga_spec);
	        }
	        else {
	        	tabHost.addTab(jornadas_liga_spec);
	        	tabHost.addTab(General_liga_spec);
	        }
	        
	        tabHost.setOnTabChangedListener(new OnTabChangeListener() {
				public void onTabChanged(String tabId) {	
				}
			});
	        
	 }//end_onCreate
	 
	 
	 @Override
	 public boolean onCreateOptionsMenu(Menu menu) {
	     MenuInflater inflater = getMenuInflater();
	     inflater.inflate(R.menu.menu_chat, menu);
	     return true;
	 }
	 
	 
	 @Override
	 public boolean onOptionsItemSelected(MenuItem item) {
	     switch (item.getItemId()) {
	         case R.id.chat:     
	        	 	Intent intent_chat = new Intent(TabHost_Liga.this, ChatActivity.class);
	        	 	intent_chat.putExtra("ligaid", Liga_Id);
	        		startActivity(intent_chat);
	              break;   
	     }
	     return true;
	 }

}//end_TabHost_Liga
